﻿
    using System;
    using System.IO;
    using System.Text.RegularExpressions;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public partial class SendMessage : PageBase
    {


        protected void btnImport_Click(object sender, EventArgs e)
        {
            string strMobileList = "";
            string strUploadPath = this.btnUploadMobile.FileName;
            string strSavePath = base.Server.MapPath("~/Upload/MobileNumber/Mobile.txt");
            if (strUploadPath == "")
            {
                base.OutputWarn("请先点击浏览按钮选择一个有手机号码的记事本文件，再导入号码。");
            }
            else if (strUploadPath.Substring(strUploadPath.LastIndexOf(".") + 1, (strUploadPath.Length - strUploadPath.LastIndexOf(".")) - 1).ToLower() != "txt")
            {
                base.OutputWarn("选择文件的文件格式错误，请重新选择记事本文件。");
            }
            else
            {
                this.btnUploadMobile.PostedFile.SaveAs(strSavePath);
            }
            if (File.Exists(strSavePath))
            {
                using (StreamReader myreader = File.OpenText(strSavePath))
                {
                    string[] strMobile = myreader.ReadToEnd().Replace("\r\n", ",").Split(new char[] { ',' });
                    for (int i = 0; i < strMobile.Length; i++)
                    {
                        Match m = Regex.Match(strMobile[i], @"^[1][3,4,5,8]\d{9}");
                        if (m.Success && (strMobileList.IndexOf(m.Value) < 0))
                        {
                            strMobileList = strMobileList + m.Value + ",";
                        }
                    }
                    this.txtCustomReceiver.Value = (strMobileList.Length > 1) ? strMobileList.Remove(strMobileList.Length - 1) : "";
                    return;
                }
            }
            base.OutputWarn("导入号码失败，请重新导入。");
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                if (!string.IsNullOrEmpty(base.Request["modiles"]))
                {
                    this.txtMemReceiver.Value = base.Request.QueryString["modiles"];
                }
                else
                {
                    this.txtMemReceiver.Attributes.Add("display", "none");
                }
                this.chkSms.Checked = base.curParameter.bolSms;
                PubFunction.BindSmsTemplate_new(this.sltCustomSmsTemplate);
                PubFunction.BindSmsTemplate(this.sltMemSmsTemplate);
                PubFunction.BindMemLevelSelect(this.sltMemLevelID, true);
                PubFunction.BindShopSelect(base._UserShopID, this.sltShop, true);
            }
        }
    }


